package com.biz.primus.ms.tms.dao.po;


import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;


/**
 * @author JKLiues
 * @date 2017/11/21
 */
@Getter
@Setter
@Entity
@Table(name = "init_upgrade")
public class UpgradePo extends BaseEntity {
    private static final long serialVersionUID = 4003734130728921048L;

    @Column
    private String os;

    @Column
    private Boolean isForce;

    @Column
    private String version;

    @Column
    private String info;

    @Column
    private String url;

    @Column
    private String md5;

    @Column
    private Boolean inHouse;

    @Column
    @Enumerated(EnumType.STRING)
    private CommonStatus status = CommonStatus.ENABLE;


    public static long versionToScore(String version) {
        if (StringUtils.isNotBlank(version)) {
            if (version.indexOf(".") > 0) {
                String[] arr = version.trim().split("\\.");
                if (arr.length == 3) {
                    return Long.parseLong(arr[0]) * 1000000 + Integer.parseInt(arr[1]) * 1000
                            + Integer.parseInt(arr[2]);
                }
            } else {
                return Long.parseLong(version);
            }
        }
        return 0;
    }

    public long versionToScore() {
        return versionToScore(version);
    }


}
